<!--
* description: 采购单制作新增编辑 表格的备件信息弹出框（含输入框）
-->
<template>
  <section class="carTypeConfig">
    <el-input
      style="width:100%;"
      placeholder="请选择"
      v-model="curValue"
      :disabled="disabled"
      size="small"
      suffix-icon="el-icon-menu"
      @focus="getFocusCode"
      :readonly="readonly"
      class="tableTemplate"
    ></el-input>
    <PartInfo
      :popupsVisible="curPopupsVisible"
      :codeField="codeField"
      :textField="textField"
      :comType="comType"
      :valueObject="curValueObject"
      :popupsKey="popupsKey"
      :code="modelCode"
      :text="modelText"
      :key="curPopupsKey"
      :isMul="isMul"
      :returnCodeField="returnCodeField"
      :returnTextField="returnTextField"
      @changeCode="getComponentCode1"
      :SUPPLIER_CODE="SUPPLIER_CODE"
      ref="dialogComponent"
    ></PartInfo>
  </section>
</template>
<script>
import { searchInputMixins } from "@/components/mixins/searchInputMixins";
import { valueObjectMixins } from "@/components/mixins/valueObjectMixins";
import PartInfo from "@/components/wms/wmsEjectWindows/wmsTableInputPartInfo/edit";
export default {
  // 组件混入对象
  mixins: [searchInputMixins, valueObjectMixins],
  components: {
    PartInfo
  },
  props: {
    rowData: { type: Object, default: {} },
    rowIndex: { type: Number, require: true },
    SUPPLIER_CODE: { type: String, default: "" },
    PartNo: { type: String, default: "" }
  },
  data() {
    return {
      row: {},
      curLabelName: this.labelName === "" ? "备件编码" : this.labelName,
      curValue: ""
    };
  },
  watch: {
    SUPPLIER_CODE() {
      this.curValue = "";
    },
    PartNo(val) {
      this.curValue = val;
    }
  },
  methods: {
    getFocusCode(e) {
      if (
        this.$refs[this.inputRef] &&
        this.$refs[this.inputRef].focused !== true
      ) {
        return;
      }
      // disabled不能为true
      if (!this.curPopupsVisible && this.disabled !== true) {
        e.target.blur();
        if (!this.SUPPLIER_CODE) {
          this.$message({
            message: "请先选择合作伙伴编号"
          });
          return;
        }
        // 判断必须查询条件字段
        if (
          this.mustFields &&
          this.mustFields !== null &&
          this.curValueObject
        ) {
          const arrFields = this.mustFields.split("|");
          for (var i in arrFields) {
            if (
              !this.curValueObject[arrFields[i]] ||
              this.curValueObject[arrFields[i]] === ""
            ) {
              this.onHasNoMust(this.mustFields, this.curValueObject);
              return;
            }
          }
        }
        this.curPopupsVisible = true;
        this.curPopupsKey = this.codeField + this.$utils.generateId();
      }
    },
    getComponentCode1(
      code,
      text,
      codeField,
      comType,
      popupsKey,
      textField,
      otherField,
      selectData
    ) {
      this.curPopupsVisible = false;
      this.curPopupsKey = this.$utils.generateId();
      if (!code) {
        return;
      }
      var parent = this.$utils.getHasFormFieldParentComponent(this);
      let flag = false;
      let parentTableData = JSON.parse(JSON.stringify(parent.tableData));
      parentTableData = parentTableData.filter(
        (item, index) => index !== this.rowData.$index
      );
      parentTableData.forEach(item => {
        if (selectData[0].PART_NO === item.PART_NO) {
          flag = true;
        }
      });
      if (flag) {
        this.$alert(`${selectData[0].PART_NAME}备件不能重复选择`, "提示", {
          confirmButtonText: "关闭"
        });
        return;
      }
      this.row = selectData[0];
      this.curValue = this.row.PART_NO;
      this.$emit("checkPartDataRow", this.row, this.rowIndex);
    }
  }
};
</script>
<style type="text/css" lang="scss" scoped>
/deep/ .tableTemplate .el-input__inner {
  border: none;
}
</style>
